﻿using NetWing.Common.Data.SqlServer;
using NetWing.Model;
using System;
using System.Data;

namespace NetWing.BPM.Admin.JydWodrmb
{
    public partial class print_printshqsd : System.Web.UI.Page
    {
        protected string OrderID;
        protected string comname;
        protected string connman;
        protected string tel;
        protected string adddate;
        protected string deliveryDate;
        protected string jjy;
        protected string ywy;
        protected string explain;
        protected string huofa;
        protected string ys;
        protected string jedx;
        protected string jexx;
        protected string yufuk;
        protected string yufukuana;

        protected string fumoa;
        protected string fumob;
        protected string tana;
        protected string tanb;
        protected string uva;
        protected string uvb;
        protected string yaa;
        protected string yab;
        protected string db;
        protected string sh;
        protected string zheye;
        protected string zd;
        protected string bh;
        protected string sk;
        protected string dda;
        protected string ddb;
        protected string dddd;
        protected string dddda;
        protected string ddddb;
        protected string printtype;
        protected string aaaaa;



        protected string sl;
        protected string dj;
        protected string je;
        protected string shslo;

        protected JydOrderModel model;
        protected JydOrderDetailModel model1;
        protected string bzhua;
        public DataTable dt = null;
        public DataTable dte = null;
        public DataTable dtu = null;
        public string xx;
        public DataTable dataTable;
        protected void Page_Load(object sender, EventArgs e)
        {
            string pid = Request["KeyId"];//主表ID
            string dateii = Request["OrderID"];//orderid
            aaaaa = Request["aaaaa"];//输入发货数量
            string songhuos = Request["songhuos"];
            bzhua = Request["bzhua"];
            string id = Request["id"];
            xx = Request["xx"];
            string yspmc = Request["yspmc"];
           
            string sql = "select * from jydOrderDetail where  orderid='" + dateii + "' and keyid in (" + Request["dids"] + ")";//明细表
            //更新明细单送货签收时间和签收状态
            SqlEasy.ExecuteNonQuery("update jydOrderDetail set qianshou=1,songhuo='" + DateTime.Now.ToString() + "' where  orderid='" + dateii + "' and keyid in (" + Request["dids"] + ")");
            //更新单子送货签收状态
            SqlEasy.ExecuteNonQuery("update jydorder set status=status+',2',mystatus=2 where keyid=" + pid + "");

            string sqle = "select * from jydOrder where OrderID='" + dateii + "' and KeyId=" + pid;

            string sqlu = "select * from jydOrderDetailSH where Orderid='" + dateii + "' and songhuos='" + songhuos + "'";
            dt = SqlEasy.ExecuteDataTable(sql);
            dte = SqlEasy.ExecuteDataTable(sqle);
            dtu = SqlEasy.ExecuteDataTable(sqlu);
            string shname = "";
            foreach (DataRow dr in dte.Rows)
            {
                shname += dr["OrderID"].ToString() + ",";
            }


            shname = shname.Substring(0, shname.Length - 1);

            model = new JydOrderModel();
            model1 = new JydOrderDetailModel();

            if (dte.Rows.Count > 0)
            {
                model.OrderID = dte.Rows[0]["OrderID"].ToString();
                model.comname = dte.Rows[0]["comname"].ToString();
                model.connman = dte.Rows[0]["connman"].ToString();
                model.tel = dte.Rows[0]["tel"].ToString();
                adddate = dte.Rows[0]["adddate"].ToString();
                deliveryDate = dte.Rows[0]["deliveryDate"].ToString();
                model.jjy = dte.Rows[0]["jjy"].ToString();
                model.ywy = dte.Rows[0]["ywy"].ToString();
                model.explain = dte.Rows[0]["explain"].ToString();
                model.huofa = dte.Rows[0]["huofa"].ToString();
                model.ys = dte.Rows[0]["ys"].ToString();
                model.jedx = dte.Rows[0]["jedx"].ToString();
                jexx = dte.Rows[0]["jexx"].ToString();
                yufuk = dte.Rows[0]["yufuk"].ToString();
                model.yufukuana = dte.Rows[0]["yufukuana"].ToString();

                OrderID = model.OrderID;
                comname = model.comname;
                connman = model.connman;
                tel = model.tel;
                jjy = model.jjy;
                ywy = model.ywy;
                explain = model.explain;
                huofa = model.huofa;
                ys = model.ys;
                jedx = model.jedx;
                jedx = model.jedx;
                yufukuana = model.yufukuana;

            }
            else
            {

            }


            if (dt.Rows.Count > 0)
            {
                fumoa = dt.Rows[0]["fumoa"].ToString();
                fumob = dt.Rows[0]["fumob"].ToString();
                tana = dt.Rows[0]["tana"].ToString();
                tanb = dt.Rows[0]["tanb"].ToString();
                uva = dt.Rows[0]["uva"].ToString();
                uvb = dt.Rows[0]["uvb"].ToString();
                yaa = dt.Rows[0]["yaa"].ToString();
                yab = dt.Rows[0]["yab"].ToString();
                db = dt.Rows[0]["db"].ToString();
                sh = dt.Rows[0]["sh"].ToString();
                zheye = dt.Rows[0]["zheye"].ToString();
                zd = dt.Rows[0]["zd"].ToString();
                bh = dt.Rows[0]["bh"].ToString();
                sk = dt.Rows[0]["sk"].ToString();
                //dda = dt.Rows[0]["dddda"].ToString();
                //ddb = dt.Rows[0]["ddddb"].ToString();
                dddd = dt.Rows[0]["dddd"].ToString();
                printtype = dt.Rows[0]["PrintType"].ToString();
                sl = dt.Rows[0]["sl"].ToString();
                dj = dt.Rows[0]["dj"].ToString();
            }
            else
            {

            }

            if (xx == "")
            {
                if (aaaaa == "")
                {
                    return;
                }
                else
                {
                    int shslo = SqlEasy.ExecuteNonQuery("insert into jydOrderDetailSH values('" + Convert.ToInt32(id) + "','" + yspmc + "','" + printtype + "','" + Convert.ToDecimal(string.IsNullOrEmpty(sl) ? "0" : sl) + " ','" + Convert.ToDecimal(dj) + "','" + Convert.ToDecimal(je) + "','" + Convert.ToDateTime(DateTime.Now.ToString()) + "','" + Convert.ToDecimal(aaaaa) + "','" + dateii + "','" + (string.IsNullOrEmpty(bzhua) ? "无" : bzhua) + "')");

                }

                if (dtu.Rows.Count > 0)
                {
                    sl = dtu.Rows[0]["songhuos"].ToString();
                }


            }
        }
    }
}
